package controllers

import (
	"github.com/astaxie/beego"
	"github.com/gookit/goutil/strutil"
	"http_monitor/models"
)

type LoginController struct {
	beego.Controller
}

func (c *LoginController) Get() {
	c.Data["Website"] = "beego.me"
	c.Data["Email"] = "astaxie@gmail.com"
	c.TplName = "login.tpl"
}
func (c *LoginController) Post() {
	user := models.User{}

	if err := c.ParseForm(&user); err == nil {
		if user.Account == "admin" && strutil.Md5(user.Password) == "8bf55c378ef2e86808d41ebbc810bdbb" {
			c.SetSession("user", user)
			c.Redirect("/index", 302)
		}

	} else {
		c.Data["error"] = "账号或密码错误！"
		c.TplName = "login.tpl"
	}

}
